//
// Created by REEJI2219 on 2024-08-14.
//
#include <iostream>
using namespace std;
typedef int Element;
class Node {
public:
    Element data;
    Node *next;
    Node() {
        this->data=0;
        this->next=nullptr;
    }
    ~Node();
};
class LinkQueue {
private:
    Node *front;//头节点
    Node *rear;//尾节点
public:
    LinkQueue() {
        this->front = new Node();
        this->rear = this->front;
    }
    ~LinkQueue() {
        Node *current = rear;
        while (current->next) {
            Node *tmp = current;
            current=current->next;
            free(tmp);
        }
        front=nullptr;
        rear=nullptr;
    }
    bool enQueue(Element element) {
        Node *tmp =  new Node();
        if(tmp==nullptr) {
            return false;
        }
        tmp->data = element;
        //队尾加入当前节点
        front->next=tmp;
        //队尾后移
        front=tmp;
    }
    bool deQueue(Element *element) {
        //对头等于队尾
        if(rear==front) {
            *element = 0;
           return  false;
        }
        Node *current = rear->next;
        *element  = current->data;
        rear->next = current->next;
        //如果头节点的尾部是空指针，说明没有数据，此时则为空队列
        if(!rear->next) {
            front=rear;
        }
        free(current);
        return true;
    }
    bool isEmpty() {
        return rear==front;
    }

    /**
     *
     * @return 打印队头到队尾的数据
     */
    bool printQueue() {
        Node *current = rear->next;
        while (current) {
            printf("%d ",current->data);
            current = current->next;
        }
        printf("\n");
    }
};

// int main(int argc) {
//     LinkQueue *link_queue = new LinkQueue();
//     link_queue->enQueue(1);
//     link_queue->enQueue(2);
//     link_queue->enQueue(3);
//     link_queue->printQueue();
//     Element out;
//     link_queue->deQueue(&out);
//     printf("%d \n",out);
//     link_queue->deQueue(&out);
//     printf("%d \n",out);
//     link_queue->deQueue(&out);
//     printf("%d \n",out);
//     bool status = link_queue->deQueue(&out);
//     printf("status %d out %d",status,out);
// }
